﻿
Public Class cTipoClientes

    Private lDrTipoCliente As dsTercero.TER_TIPOCLIENTESRow

    Sub New(ByVal IdTipo As String)
        Try
            Dim daTipoCli As New dsTerceroTableAdapters.TER_TIPOCLIENTESTableAdapter
            Dim dtTipoCli As dsTercero.TER_TIPOCLIENTESDataTable = daTipoCli.GetDataByIdTipoCliente(IdTipo)
            If dtTipoCli.Rows.Count > 0 Then
                lDrTipoCliente = dtTipoCli.Rows(0)
            Else
                Throw New Exception("Tipo Cliente no existe, verifique e intente de nuevo")
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub

    Public ReadOnly Property idTipo() As String
        Get
            Return lDrTipoCliente.IDTIPO
        End Get
    End Property

    Public ReadOnly Property Descripcion() As String
        Get
            Return lDrTipoCliente.DESCRIPCION
        End Get
    End Property

    Protected Overrides Sub Finalize()
        lDrTipoCliente = Nothing
    End Sub
End Class


Public Class cClientes

    Private lDtClientes As dsTercero.TER_CLIENTESDataTable
    Private LiCanales As cCanales
    Private LiFormaPago As cFormasPago
    Private LiTipoCliente As cTipoClientes
    Private lDrCli As dsTercero.TER_CLIENTESRow

    Sub New(ByVal idCliente As String)
        Try
            Dim daCli As New dsTerceroTableAdapters.TER_CLIENTESTableAdapter
            lDtClientes = daCli.GetDataByIdCliente(idCliente)
            If lDtClientes.Rows.Count > 0 Then
                lDrCli = lDtClientes.Rows(0)
                LiFormaPago = New cFormasPago(lDrCli.IDFORMAPAGO)
                LiTipoCliente = New cTipoClientes(lDrCli.IDTIPO)
                If Not lDrCli.IsIDCANALNull Then _
                    LiCanales = New cCanales(lDrCli.IDCANAL)
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub
    Public Sub SeekClienteBySucursal(ByVal Sucursal As Integer)
        Try
            Dim drCli As dsTercero.TER_CLIENTESRow = lDtClientes.Rows.Find(New Object() {lDrCli.IDCLIENTE, Sucursal})
            If drCli IsNot Nothing Then
                lDrCli = drCli
                LiFormaPago = New cFormasPago(lDrCli.IDFORMAPAGO)
                LiTipoCliente = New cTipoClientes(lDrCli.IDTIPO)
                If Not lDrCli.IsIDCANALNull Then _
                    LiCanales = New cCanales(lDrCli.IDCANAL)
            Else
                Throw New Exception("No existe cliente para esta sucursal, verifique e intente de nuevo")
            End If
        Catch ex As Exception
            cError.SalvaError(ex, "Samuel")
            Throw ex
        End Try
    End Sub
    Public ReadOnly Property BodegaConsignacion() As String
        Get
            Return cGeneral.NToCad(lDrCli("IDBODEGA"))
        End Get
    End Property
    Public ReadOnly Property idCliente() As String
        Get
            Return lDrCli("IDCLIENTE")
        End Get
    End Property

    Public ReadOnly Property Sucursal() As Int16
        Get
            Return lDrCli("SUCURSAL")
        End Get
    End Property

    Public ReadOnly Property Cupo() As Double
        Get
            Return cGeneral.NZ(lDrCli("CUPO"))
        End Get
    End Property

    Public ReadOnly Property idCanal() As String
        Get
            Return cGeneral.NToCad(lDrCli("IDCANAL"))
        End Get
    End Property

    Public ReadOnly Property idFormaPago() As String
        Get
            Return lDrCli("IDFORMAPAGO")
        End Get
    End Property

    Public ReadOnly Property idTipo() As String
        Get
            Return lDrCli("IDTIPO")
        End Get
    End Property

    Public ReadOnly Property NombreEstablecimiento() As String
        Get
            Return lDrCli("NOMBREESTABLECIMIENTO")
        End Get
    End Property

    Public ReadOnly Property iCanales() As cCanales
        Get
            Return LiCanales
        End Get
    End Property

    Public ReadOnly Property iFormaPago() As cFormasPago
        Get
            Return LiFormaPago
        End Get
    End Property

    Public ReadOnly Property iTipoCliente() As cTipoClientes
        Get
            Return LiTipoCliente
        End Get
    End Property

    Public ReadOnly Property idVendedor() As String
        Get
            Return cGeneral.NToCad(lDrCli("IDVENDEDOR"))
        End Get
    End Property

    Public ReadOnly Property idListaGlobal() As String
        Get
            Return cGeneral.NToCad(lDrCli("IDLISTAGLOBAL"))
        End Get
    End Property

    Public ReadOnly Property estado() As Boolean
        Get
            Return lDrCli.ESTADO
        End Get
    End Property

    Protected Overrides Sub Finalize()
        lDrCli = Nothing
        lDtClientes = Nothing
    End Sub
End Class

